



// pages/photo/photo.js
const app = getApp()
Page({
  data: {
    //info指的是图片的信息=>base64
    info: "",
    //msg指的是返回的结果信息
    msg: ""
  },

  onLoad: function () {},

  opLoad: function () {
    var that = this
    wx.request({
      url: 'http://172.23.207.77:8080/picInfo',
      method: 'POST',
      data: {
        'picmsg': res.data.info
      },
      //data数据太长了，需要这个来搞格式
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res.data)
      }
    })
  },


  record() {
    this.data.cameraContext = wx.createCameraContext()
    this.data.cameraContext.takePhoto({
      quality: "low", //图片质量
      success: res => {
        //res.tempImagePath照片文件在手机内的的临时路径
        let tempImagePath = res.tempImagePath
        wx.saveFile({
          tempFilePath: tempImagePath,
          success: function (res) {
            //返回保存时的临时路径 res.savedFilePath
            const savedFilePath = res.savedFilePath
            // 保存到本地相册
            wx.saveImageToPhotosAlbum({
              filePath: savedFilePath,
            })
            var that = this//////////////////////////////////////
            wx.getFileSystemManager().readFile({
              filePath: res.savedFilePath, //选择图片返回的相对路径
              encoding: 'base64', //编码格式
              success: res => { //成功的回调
                var str = res.data
                var that = this
                wx.request({
                  url: 'http://172.23.207.77:8080/picInfo',
                  method: 'POST',
                  data: {
                    'picmsg': str
                  },
                  //data数据太长了，需要这个来搞格式
                  header: {
                    "Content-Type": "application/x-www-form-urlencoded"
                  },
                  success: function (result) {
                    console.log(result.data)
                    let datamsg=JSON.stringify(result.data);
                    wx.navigateTo({
                      url: 'image?datamsg=' + datamsg,
                    })
                  }//获取后端数据的success
                  
                })
              },//从后端成功返回的success
            })
          },//保存成功的success
          //保存失败回调（比如内存不足）
          fail: console.log
        })//保存图片的success
      },//拍好照片的success
    })

  },//record

  back: function(e) {
    wx.navigateBack({
      delta: 1
    });
  }


})